package com.ruoyi.basebill.service.impl;

import java.util.List;

import com.ruoyi.basebill.mapper.TWfzRemunerationMapper;
import com.ruoyi.basebill.service.ITWfzRemunerationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.basebill.domain.TWfzRemunerationentry;
import com.ruoyi.basebill.domain.TWfzRemuneration;

/**
 * 薪酬总表Service业务层处理
 *
 * @author ruoyi
 * @date 2022-12-12
 */
@Service
public class TWfzRemunerationServiceImpl implements ITWfzRemunerationService
{
    @Autowired
    private TWfzRemunerationMapper tWfzRemunerationMapper;

    /**
     * 查询薪酬总表
     *
     * @param fid 薪酬总表主键
     * @return 薪酬总表
     */
    @Override
    public TWfzRemuneration selectTWfzRemunerationByFid(Long fid)
    {
        return tWfzRemunerationMapper.selectTWfzRemunerationByFid(fid);
    }

    /**
     * 查询薪酬总表列表
     *
     * @param tWfzRemuneration 薪酬总表
     * @return 薪酬总表
     */
    @Override
    public List<TWfzRemuneration> selectTWfzRemunerationList(TWfzRemuneration tWfzRemuneration)
    {
        return tWfzRemunerationMapper.selectTWfzRemunerationList(tWfzRemuneration);
    }

    /**
     * 新增薪酬总表
     *
     * @param tWfzRemuneration 薪酬总表
     * @return 结果
     */
    @Transactional
    @Override
    public int insertTWfzRemuneration(TWfzRemuneration tWfzRemuneration)
    {
        int rows = tWfzRemunerationMapper.insertTWfzRemuneration(tWfzRemuneration);
        insertTWfzRemunerationentry(tWfzRemuneration);
        return rows;
    }

    /**
     * 修改薪酬总表
     *
     * @param tWfzRemuneration 薪酬总表
     * @return 结果
     */
    @Transactional
    @Override
    public int updateTWfzRemuneration(TWfzRemuneration tWfzRemuneration)
    {
        tWfzRemunerationMapper.deleteTWfzRemunerationentryByFparentid(tWfzRemuneration.getFid());
        insertTWfzRemunerationentry(tWfzRemuneration);
        return tWfzRemunerationMapper.updateTWfzRemuneration(tWfzRemuneration);
    }

    /**
     * 批量删除薪酬总表
     *
     * @param fids 需要删除的薪酬总表主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTWfzRemunerationByFids(Long[] fids)
    {
        tWfzRemunerationMapper.deleteTWfzRemunerationentryByFparentids(fids);
        return tWfzRemunerationMapper.deleteTWfzRemunerationByFids(fids);
    }

    /**
     * 删除薪酬总表信息
     *
     * @param fid 薪酬总表主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTWfzRemunerationByFid(Long fid)
    {
        tWfzRemunerationMapper.deleteTWfzRemunerationentryByFparentid(fid);
        return tWfzRemunerationMapper.deleteTWfzRemunerationByFid(fid);
    }

    /**
     * 新增薪酬总分录信息
     *
     * @param tWfzRemuneration 薪酬总表对象
     */
    public void insertTWfzRemunerationentry(TWfzRemuneration tWfzRemuneration)
    {
        List<TWfzRemunerationentry> tWfzRemunerationentryList = tWfzRemuneration.getTWfzRemunerationentryList();
        Long fid = tWfzRemuneration.getFid();
        if (StringUtils.isNotNull(tWfzRemunerationentryList))
        {
            List<TWfzRemunerationentry> list = new ArrayList<TWfzRemunerationentry>();
            for (TWfzRemunerationentry tWfzRemunerationentry : tWfzRemunerationentryList)
            {
                tWfzRemunerationentry.setFparentid(fid);
                list.add(tWfzRemunerationentry);
            }
            if (list.size() > 0)
            {
                tWfzRemunerationMapper.batchTWfzRemunerationentry(list);
            }
        }
    }

    /**
     * 批量审核薪酬总表
     *
     * @param fids 需要审核的薪酬总表主键
     * @return 结果
     */
    @Transactional
    @Override
    public int auditTWfzRemunerationByFids(Long[] fids)
    {
        return tWfzRemunerationMapper.auditTWfzRemunerationByFids(fids);
    }

    /**
     * 批量反审核薪酬总表
     *
     * @param fids 需要反审核的薪酬总表主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deAuditTWfzRemunerationByFids(Long[] fids)
    {
        return tWfzRemunerationMapper.deAuditTWfzRemunerationByFids(fids);
    }

    /**
     * 批量废弃薪酬总表
     *
     * @param fids 需要废弃的薪酬总表主键
     * @return 结果
     */
    @Transactional
    @Override
    public int disuseTWfzRemunerationByFids(Long[] fids)
    {
        return tWfzRemunerationMapper.disuseTWfzRemunerationByFids(fids);
    }

    /**
     * 对单据状态进行改变
     * @param fids
     * @param fstate
     * @return
     */
    @Override
    public int operation(Long[] fids, String fstate) {

        return tWfzRemunerationMapper.operation(fids,fstate);
    }

}
